//Shkolnij Rostislav
package CalculationCore;

import java.util.Vector;


public class CButtonTable {
	private Vector<CButtonEntry> ButtonTable;
	
	public CButtonTable()
	{
		ButtonTable = new Vector<CButtonEntry>(10, 10);
	}
	// for simple buttons
	public void add(int id, int pos, String type, String sign, String name) 
	{
		ButtonTable.add(new CButtonEntry(id, pos, type, sign, "", name));
	}
	// for compound buttons
	public void add(int id, int pos, String type, String sign, String comp, String name)
	{
		ButtonTable.add(new CButtonEntry(id, pos, type, sign, comp, name));
	}
	
	public CButtonEntry get(int i)
	{
		return ButtonTable.get(i);
	}
	
	public int size()
	{
		return ButtonTable.size();
	}
	
	public int findPosByID(int seekid)
	{
		int res = -1;
		boolean flag = true;
		CButtonEntry temp;
		for(int i=0; i<ButtonTable.size() && flag; i++)
		{
			temp = ButtonTable.get(i);
			if(temp.getiBtnID() == seekid)
			{
				res = temp.getiBtnPos();
				flag = false;
			}
		}
		return res;
	}
	
	public CButtonEntry findEntryByID(int seekid)
	{
		CButtonEntry res = null;
		boolean flag = true;
		CButtonEntry temp;
		for(int i=0; i<ButtonTable.size() && flag; i++)
		{
			temp = ButtonTable.get(i);
			if(temp.getiBtnID() == seekid)
			{
				res = temp;
				flag = false;
			}
		}
		return res;
	}
	
	public int findIDByPos(int seekid)
	{
		int res = -1;
		boolean flag = true;
		CButtonEntry temp;
		for(int i=0; i<ButtonTable.size() && flag; i++)
		{
			temp = ButtonTable.get(i);
			if(temp.getiBtnPos() == seekid)
			{
				res = temp.getiBtnID();
				flag = false;
			}
		}
		return res;
	}
	
	public String findSignByPos(int seekpos)
	{
		String res = "";
		boolean flag = true;
		CButtonEntry temp;
		for(int i=0; i<ButtonTable.size() && flag; i++)
		{
			temp = ButtonTable.get(i);
			if(temp.getiBtnPos() == seekpos)
			{
				res = temp.getsBtnSign();
				flag = false;
			}
		}
		return res;
	}
}
